package image

import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import java.io.File
import java.awt.Color

/**
 * Created by IntelliJ IDEA.
 * User: denny
 * Date: Jun 22, 2010
 * Time: 10:11:36 AM
 * To change this template use File | Settings | File Templates.
 */

object NormalizedRGB extends Application{
  val size=400
  val imgNew = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB)
  for( i<-0 until size; j<-0 until size){
    val r = i.toDouble/size
    val g = j.toDouble/size
    val b = 1 - r - g
    if(b>=0){
      val k = 255 / r.max(g).max(b)
      val color = new Color( (r*k).round.toInt, (g*k).round.toInt, (b*k).round.toInt )
      val color2 = new Color( (r*k/2).round.toInt, (g*k/2).round.toInt, (b*k/2).round.toInt )
      imgNew.setRGB(i, j, color.getRGB)
      imgNew.setRGB(size-i-1, size-j-1, color2.getRGB)
    }
  }
  ImageIO.write(imgNew, "jpeg", new File("/tmp/normalizedRGB.jpeg"))
  println( "File ready" )

}